package cn.bxshey.auth.config;

import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.stereotype.Component;

/**
 * @作者：不想说话而已
 * @Date：2023/11/30 19:28
 * 根据名称生成 对应的bean
 */
@Component
public class BeanFactoryCustomize implements BeanFactoryAware {
    private static BeanFactory beanFactory;
    @Override
    public void setBeanFactory(@NotNull BeanFactory beanFactory) throws BeansException {
        BeanFactoryCustomize.beanFactory = beanFactory;
    }

    //根据名字获取bean
    public static Object getBean(String beanName) {
        return beanFactory.getBean(beanName);
    }

    //根据名字判断是否有这个bean
    public static boolean checkContainsBean(String beanName) {
        return beanFactory.containsBean(beanName);
    }
}
